//pinia实现用户登录，保存信息功能
import {defineStore} from 'pinia';
import {ref} from 'vue'
import {useEnterpriseStore} from "@/store/enterprise";
export const useUserStore = defineStore('user', ()=>{
    const userInfo = ref<UserItem>({});
    const token = ref<string>('');
    const enterprise = ref<EnterpriseItem>()
    const enterpriseList = ref<EnterpriseItem[]>()

    const store = useEnterpriseStore();
    const setUserInfo = (data:LoginResponse)=>{
        userInfo.value = data.userinfo;
        token.value = data.token;
        store.setEnterpriseList(data.enterprise)
    }
    return {
        userInfo,
        token,
        setUserInfo,
        enterprise,
        enterpriseList
    }
},{persist: true});